<?php

namespace app\admin\controller;

use app\app\model\ProjectPhoneModel;
use app\BaseController;


class Phone extends BaseController
{

    public function add()
    {
        $data = $this->request->param();
        ProjectPhoneModel::create($data);
        $this->success('success');
    }

    public function update(){
        $data = $this->request->param();
        $id = $data['id'];
        unset($data['id']);
        ProjectPhoneModel::where('id',$id)->update($data);
        $this->success('success');
    }

    public function del(){
        $data = $this->request->param();
        ProjectPhoneModel::where('id', 'in', $data)->delete();
        $this->success('success');
    }

    public function index(){
        $pageSize = input('pageSize','20');
        //筛选条件
        $data = $this->request->param();

        $where[] = ['state', '=', '正常'];
        //项目名称
        if (isset($data['name'])) $where[] = ['name', 'LIKE', '%' . $data['name'] . '%'];
        if (isset($data['department'])) $where[] = ['department', 'LIKE', '%' . $data['department'] . '%'];
        if (isset($data['company_name'])) $where[] = ['company_name', 'LIKE', '%' . $data['company_name'] . '%'];
        if (isset($data['position'])) $where[] = ['position', 'LIKE', '%' . $data['position'] . '%'];
        if (isset($data['city'])) $where[] = ['city', 'LIKE', '%' . $data['city'] . '%'];

        $list = ProjectPhoneModel::where($where)->paginate($pageSize);
        $this->success('success',$list);
    }
}
